package com.ruoyi.web.controller.base;

import com.ruoyi.base.domain.BaseAbout;
import com.ruoyi.base.service.IBaseAboutService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 关于我们Controller
 *
 * @author zzp
 * @date 2022-11-27
 */
@RestController
@RequestMapping("/base/about")
public class BaseAboutController extends BaseController {
    @Autowired
    private IBaseAboutService baseAboutService;

    /**
     * 查询关于我们列表
     */
    @PreAuthorize("@ss.hasPermi('base:about:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseAbout baseAbout) {
        startPage();
        List<BaseAbout> list = baseAboutService.selectBaseAboutList(baseAbout);
        return getDataTable(list);
    }

    /**
     * 导出关于我们列表
     */
    @PreAuthorize("@ss.hasPermi('base:about:export')")
    @Log(title = "关于我们", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseAbout baseAbout) {
        List<BaseAbout> list = baseAboutService.selectBaseAboutList(baseAbout);
        ExcelUtil<BaseAbout> util = new ExcelUtil<BaseAbout>(BaseAbout.class);
        util.exportExcel(response, list, "关于我们数据");
    }

    /**
     * 获取关于我们详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:about:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(baseAboutService.selectBaseAboutById(id));
    }

    /**
     * 新增关于我们
     */
    @PreAuthorize("@ss.hasPermi('base:about:add')")
    @Log(title = "关于我们", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseAbout baseAbout) {
        baseAbout.setCreateBy(getUsername());
        return toAjax(baseAboutService.insertBaseAbout(baseAbout));
    }

    /**
     * 修改关于我们
     */
    @PreAuthorize("@ss.hasPermi('base:about:edit')")
    @Log(title = "关于我们", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseAbout baseAbout) {
        return toAjax(baseAboutService.updateBaseAbout(baseAbout));
    }

    /**
     * 删除关于我们
     */
    @PreAuthorize("@ss.hasPermi('base:about:remove')")
    @Log(title = "关于我们", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseAboutService.deleteBaseAboutByIds(ids));
    }
}
